package com.luoc.base;

import java.util.concurrent.atomic.AtomicInteger;

/**
 * @Author: luoc
 * @Date: 2019/8/8 9:48
 */
public class DeadLockDemo {
    private static String A = "A";
    private static String B = "B";


    private AtomicInteger atomicInteger = new AtomicInteger();

    public static void main(String[] args) {
        new DeadLockDemo().deadLock();
    }

    private void deadLock() {
        Thread t1 = new Thread(() -> {
            synchronized (A) {
                try {
                    Thread.currentThread().sleep(2000);
                } catch (InterruptedException e) {
                    e.printStackTrace();
                }
                synchronized (B) {
                    System.out.println(" 1");
                }
            }
        });
        Thread t2 = new Thread(() -> {
            synchronized (B) {
                synchronized (A) {
                    System.out.println(" 2");
                }
            }
        });
        t1.start();
        t2.start();
    }
}



